<?php


namespace app\api\controller;


use app\api\model\GoodsModel;
use think\Db;
use think\Exception;

class Index extends ApiBase
{

    /**
     *
     * 安卓版本检测信息
     */
    public function androidInfo(){

       $data = Db::table('ota_android')->where(['is_open'=>1,'is_deleted'=>0,'status'=>1])
           ->field('id,android_sn,link')
           ->order('id desc')
           ->limit(1)
           ->select();
       $this->successful('查询成功',$data);
    }

    /**
     *
     * 固件OTA检测信息
     */
    public function firmwareInfo(){

        $params = input();
        if (!isset($params['id']) || empty($params['id'])){

            $this->fail('缺少车型id');
        }
        $data = Db::table('ota_firmware')->alias('f')
            ->join('ota_part p','f.part_id = p.id')
            ->join('ota_hatchback h','f.hb_id = h.id')
            ->where(['f.is_open'=>1,'f.hb_id'=>$params['id']])
            ->where(['f.is_deleted'=>0,'f.status'=>1])
            ->where(['p.is_deleted'=>0,'p.status'=>1])
            ->where(['h.is_deleted'=>0,'h.status'=>1])
            ->field('f.id,p.part_name,p.update_instruct,f.firmware_sn,f.link,h.name')
            //->distinct('p.part_name')
            ->order('f.id desc')
            ->select();
        $list = [];
        if ($data){

            $list = uniquArr($data);
        }
        $this->successful('查询成功',$list);
    }

    /**
     *
     * 车型信息
     */
    public function hatchbackList(){

        $data = Db::table('ota_hatchback')->where(['is_deleted'=>0,'status'=>1])
            ->field('id,name,code')
            ->order('id desc')
            ->select();
        $this->successful('查询成功',$data);
    }


}